package com.badminton.HubSys.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;


import com.badminton.framework.config.ServerConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.badminton.common.annotation.Log;
import com.badminton.common.core.controller.BaseController;
import com.badminton.common.core.domain.AjaxResult;
import com.badminton.common.enums.BusinessType;
import com.badminton.HubSys.domain.EquipmentHub;
import com.badminton.HubSys.service.IEquipmentHubService;
import com.badminton.common.utils.poi.ExcelUtil;
import com.badminton.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/HubSys/equipment")
@Api("装备列表")
public class EquipmentHubController extends BaseController {
    @Autowired
    private IEquipmentHubService equipmentHubService;

    @Autowired
    private ServerConfig serverConfig;

    @PreAuthorize("@ss.hasPermi('HubSys:equipment:list')")
    @GetMapping("/list")
    @ApiOperation("查询装备列表")
    public TableDataInfo list(EquipmentHub equipmentHub) {
        startPage();
        List<EquipmentHub> list = equipmentHubService.selectEquipmentHubList(equipmentHub);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('HubSys:equipment:export')")
    @Log(title = "装备列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出装备列表")
    public void export(HttpServletResponse response, EquipmentHub equipmentHub) {
        List<EquipmentHub> list = equipmentHubService.selectEquipmentHubList(equipmentHub);
        ExcelUtil<EquipmentHub> util = new ExcelUtil<>(EquipmentHub.class);
        util.exportExcel(response, list, "装备列表数据");
    }

    @PreAuthorize("@ss.hasPermi('HubSys:equipment:query')")
    @GetMapping(value = "/{equipmentid}")
    @ApiOperation("获取装备详细信息")
    public AjaxResult getInfo(@PathVariable("equipmentid") Long equipmentid) {
        return success(equipmentHubService.selectEquipmentHubByEquipmentid(equipmentid));
    }

    @PreAuthorize("@ss.hasPermi('HubSys:equipment:add')")
    @Log(title = "装备列表", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增装备")
    public AjaxResult add(@RequestBody EquipmentHub equipmentHub) {
        return toAjax(equipmentHubService.insertEquipmentHub(equipmentHub));
    }

    @PreAuthorize("@ss.hasPermi('HubSys:equipment:edit')")
    @Log(title = "装备列表", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改装备")
    public AjaxResult edit(@RequestBody EquipmentHub equipmentHub) {
        return toAjax(equipmentHubService.updateEquipmentHub(equipmentHub));
    }

    @PreAuthorize("@ss.hasPermi('HubSys:equipment:remove')")
    @Log(title = "装备列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipmentids}")
    @ApiOperation("删除装备")
    public AjaxResult remove(@PathVariable Long[] equipmentids) {
        return toAjax(equipmentHubService.deleteEquipmentHubByEquipmentids(equipmentids));
    }




}
